package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;

import com.ruoyi.system.domain.dto.AnnouncementByIdsDTO;
import com.ruoyi.system.domain.dto.AnnouncementDTO;
import com.ruoyi.system.domain.dto.EnterpriseSupplierByIdsDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Announcement;
import com.ruoyi.system.service.IAnnouncementService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公告Controller
 *
 * @author 协同
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/system/announcement")
public class AnnouncementController extends BaseController {
    @Resource
    private IAnnouncementService announcementService;

    /**
     * 查询企业公告列表
     */
    @GetMapping("/listEnterprise")
    public TableDataInfo listEnterprise(Announcement announcement) {
        startPage();
        List<Announcement> list = announcementService.listEnterprise(announcement);
        return getDataTable(list);
    }

    /**
     * 查询供应商公告列表
     */
    @GetMapping("/listSupplier")
    public TableDataInfo listSupplier(Announcement announcement) {
        startPage();
        List<Announcement> list = announcementService.listSupplier(announcement);
        return getDataTable(list);
    }

    /**
     * 获取公告详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(announcementService.selectAnnouncementById(id));
    }

    /**
     * 新增公告
     */
    @PostMapping
    public AjaxResult add(@RequestBody AnnouncementDTO dto) {
        return toAjax(announcementService.insertAnnouncement(dto));
    }

    /**
     * 修改公告
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Announcement announcement) {
        return toAjax(announcementService.updateAnnouncement(announcement));
    }

    /**
     * 发布公告
     */
    @PostMapping("/updateByIds")
    public AjaxResult updateByIds(@RequestBody AnnouncementByIdsDTO dto) {
        return toAjax(announcementService.updateByIds(dto.getIds().toArray(new Long[0])));
    }

    /**
     * 删除公告
     */
    @PostMapping("/deleteByIds")
    public AjaxResult deleteByIds(@RequestBody AnnouncementByIdsDTO dto) {
        return toAjax(announcementService.deleteByIds(dto.getIds().toArray(new Long[0])));
    }
}
